package calculators;

import algorithm.AlgorithmParameters;
import herd.Krill;
import utils.Position;
import utils.PositionMath;

import java.util.List;

public class MotionCalculator {
    private AlphaCalculator alphaCalculator = new AlphaCalculator();
    private PositionMath positionMath = new PositionMath();

    public void calculateMotion(List<Krill> herd, AlgorithmParameters algorithmParameters){
        for(Krill krill : herd){
            Position oldMotion = positionMath.multiplyPositionByScalar(krill.getMotionInduced(),algorithmParameters.inertiaWeight);
            Position alphaPosition = getAlphaPosition(herd,krill,algorithmParameters);
            Position newMotionPosition = positionMath.addPositions(alphaPosition,oldMotion);

            krill.setMotionInduced(newMotionPosition);
        }
    }

    private Position getAlphaPosition(List<Krill> herd,Krill krill, AlgorithmParameters parameters){
        Position alphaPosition = alphaCalculator.calculateAlpha(herd,krill,parameters);
        positionMath.multiplyPositionImplicitly(alphaPosition,parameters.N_MAX);
        return alphaPosition;
    }
}
